package com.neusoft.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.neusoft.bo.VirtualWalletBO;
import com.neusoft.po.VirtualWallet;

@Mapper
public interface VirtualWalletMapper {
	//作业之外的支持功能,创建一个钱包记录
	@Insert("insert into virtualWallet(userId,createTime,balance) values(#{userId},#{createTime},0)")
	@Options(useGeneratedKeys = true, keyProperty = "walletId", keyColumn = "walletId")
	public int saveWallet(VirtualWallet wallet);
	//作业之外的支持功能,获取一个钱包记录
	@Select("select* from virtualWallet where walletId=#{walletId} and userId=#{userId}")
	public VirtualWalletBO getWallet(@Param("walletId") Integer walletId, @Param("userId") String userId);
	//支持功能,更新钱包记录
	@Update("update virtualWallet set balance=#{balance} where walletId=#{walletId} and userId=#{userId}")
	public int updateWallet(VirtualWallet wallet);
	
	//支持功能，获取wallet
	@Select("select* from virtualWallet where userId=#{userId}")
	public VirtualWallet getWalletByUserId(String userId);
	
//	//增加余额
//	@Update("update virtualWallet set balance=balance+#{addAmount} where walletId=#{walletId} and userId=#{userId}")
//	public int addBalanceByUserId(Integer walletId, String userId, Double addAmount);
//	
//	//减少余额
//	@Update("update virtualWallet set balance=balance-#{minusAmount} where walletId=#{walletId} and userId=#{userId}")
//	public int minusBalanceByUserId(Integer walletId, String userId, Double minusAmount);
	
	//查询余额
	@Select("select balance from virtualWallet where userId=#{userId}")
	public Double getBalanceByUserId(String userId);
}
